import request from '@/utils/request';

// 私聊会话相关接口类型定义
export interface PrivateChat {
  chat_id: number;
  user: {
    user_id: number;
    name: string;
    avatar?: string;
  };
  other_user: {
    user_id: number;
    name: string;
    avatar?: string;
  };
  updatedAt: string;
}

// 私聊消息相关接口类型定义
export interface PrivateMessage {
  message_id: number;
  chat_id: number;
  sender_id: number;
  receiver_id: number;
  content: string;
  message_type: 'text' | 'image' | 'audio' | 'video';
  status: 'sent' | 'delivered' | 'read';
  createdAt: string;
  sender?: {
    user_id: number;
    name: string;
    avatar?: string;
  };
}

// 获取私聊会话列表
export const getPrivateChatList = (data?: { keyword?: string }) => {
  return request.post<PrivateChat[]>('/private-chat/list', data);
};

// 获取私聊会话列表（分页）
export const getPrivateChatListPage = (data: { page?: number; limit?: number; keyword?: string }) => {
  return request.post<{ list: PrivateChat[]; pagination: any }>('/private-chat/listPage', data);
};

// 获取私聊消息历史记录
export const getPrivateMessageHistory = (data: { chat_id: number; page?: number; limit?: number }) => {
  return request.post<{ 
    messages: PrivateMessage[]; 
    pagination: any 
  }>('/private-chat/history', data);
};

// 创建私聊会话
export const createPrivateChat = (data: { other_user_id: number }) => {
  return request.post<PrivateChat>('/private-chat/create', data);
};

// 删除私聊会话
export const deletePrivateChat = (data: { chat_id: number }) => {
  return request.post('/private-chat/delete', data);
};

// 更新私聊消息
export const updatePrivateMessage = (data: { message_id: number; content: string }) => {
  return request.post<PrivateMessage>('/private-message/update', data);
};

// 删除私聊消息
export const deletePrivateMessage = (data: { message_id: number }) => {
  return request.post('/private-message/delete', data);
};